package br.ufg.apkwebservice.ws;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

@Path("/login")
public class LoginResourceWs {

	private LoginService loginService = new LoginService();

	@GET
	@Produces("application/json")
	public Response logar(@QueryParam("login") String login,
			@QueryParam("senha") String senha) {

		System.out.println("LOGIN ACESSADO: login:" + login);

		Response response = null;

		if ((login != null && !login.isEmpty())
				&& (senha != null && !senha.isEmpty())) {

			// Buscar tipo de pessoa (Professor ou aluno)
			Integer id = loginService.podeLogar(login, senha);

			if (id == null) {
				response = Response.status(Response.Status.OK).entity(0)
						.build();
			} else {
				response = Response.status(Response.Status.OK).entity(id)
						.build();
			}

		} else {
			response = Response.status(Response.Status.FORBIDDEN).build();
		}

		return response;
	}
}
